package com.master5.grocerylist.credentials;


import java.util.Date;
import java.util.Locale;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/api/authantication")
public class CredentialsResource {
	CredentialsDao dao = new  CredentialsDao();
	
	@GET
	@Produces(MediaType.TEXT_PLAIN)
	@Path("/login/{account_name}/{password}/")
	public String authenticate(
			@PathParam("account_name") String account_name, 
			@PathParam("password") String password		
	){
		int info = dao.authenticate(account_name, password);
		return Integer.toString(info);
	}
	
	
	@GET
	@Produces(MediaType.TEXT_PLAIN)
	@Path("/signup/{account_name}/{password}/{name}/{surname}/{email}/{phone}/{birthdate}/{gender}/{role_id}/")
	public String signUp(
			@PathParam("account_name") String account_name, 
			@PathParam("password") String password,
			@PathParam("name") String name,
			@PathParam("surname") String surname,
			@PathParam("email") String email,
			@PathParam("phone") String phone,
			@PathParam("birthdate") String birthdate,
			@PathParam("gender") String gender,
			@PathParam("role_id") String role_id
	){	
		
		if (dao.signUp(account_name, password, name, surname, email, phone, birthdate, gender, Integer.parseInt(role_id)))
			return "Success";
		return "False";
		}
}
